package com.mujin.keji.collectionsystem.utils;

import android.content.Intent;
import android.provider.Settings;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.Constant;
import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.dialog.BaseNiceDialog;
import com.mujin.keji.collectionsystem.dialog.NiceDialog;
import com.mujin.keji.collectionsystem.dialog.ViewConvertListener;
import com.mujin.keji.collectionsystem.dialog.ViewHolder;

/**
 * 对话框工具类
 *
 * @author weishixiong
 * @Time 2018-03-19
 */
public class DialogUtils {
    /**
     * 打开权限对话框
     *
     * @param s
     */
    public static void showPerMissionDailog(final String s, final FragmentActivity activity) {
        NiceDialog.init()
                .setLayoutId(R.layout.dialog_permission)
                .setConvertListener(new ViewConvertListener() {
                    @Override
                    public void convertView(ViewHolder holder, final BaseNiceDialog dialog) {
                        dialog.setOutCancel(false);
                        TextView tvNo = (TextView) holder.getView(R.id.tv_no);
                        TextView tvOk = (TextView) holder.getView(R.id.tv_ok);
                        TextView tvContent = (TextView) holder.getView(R.id.tv_content);
                        tvContent.setText(s);
                        tvNo.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                                activity.finish();
                            }
                        });
                        tvOk.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                                Constant.Server.isToPerssionActivity = true;
                               // IntentUtils.gotoPermissionSetting();

                            }
                        });
                    }
                })

                .show(activity.getSupportFragmentManager());
    }

    /**
     * 获取地址失败提示对话框
     *
     * @param s
     */
    public static void showPerTipDailog(final String s, FragmentActivity activity) {
        NiceDialog.init()
                .setLayoutId(R.layout.dialog_adress_tips)
                .setConvertListener(new ViewConvertListener() {
                    @Override
                    public void convertView(ViewHolder holder, final BaseNiceDialog dialog) {
                        dialog.setOutCancel(false);
                        TextView tvOk = (TextView) holder.getView(R.id.tv_ok);
                        TextView tvContent = (TextView) holder.getView(R.id.tv_content);
                        tvContent.setText(s);
                        tvOk.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                            }
                        });
                    }
                })

                .show(activity.getSupportFragmentManager());

    }

    /**
     * 打开位置信息对话框
     *
     * @param s
     */
    public static void showAdressInfoDailog(final String s, final FragmentActivity activity) {
        NiceDialog.init()
                .setLayoutId(R.layout.dialog_open_adress)
                .setConvertListener(new ViewConvertListener() {
                    @Override
                    public void convertView(ViewHolder holder, final BaseNiceDialog dialog) {
                        dialog.setOutCancel(false);
                        TextView tvNo = (TextView) holder.getView(R.id.tv_no);
                        TextView tvOk = (TextView) holder.getView(R.id.tv_ok);
                        TextView tvContent = (TextView) holder.getView(R.id.tv_content);
                        tvContent.setText(s);
                        tvOk.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                activity.startActivity(intent);
                            }
                        });
                        tvNo.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                activity.finish();
                            }
                        });
                    }
                })

                .show(activity.getSupportFragmentManager());

    }

}
